package io.github.wanggit.antrpc.client.config;

import org.springframework.core.env.PropertySource;

import java.util.concurrent.ConcurrentHashMap;

public class ConfigItemPropertySource extends PropertySource<ConcurrentHashMap<String, String>> {

    private static final String CONFIG_ITEM_PROPERTY_SOURCE_NAME =
            ConfigItemPropertySource.class.getSimpleName();

    ConfigItemPropertySource() {
        super(CONFIG_ITEM_PROPERTY_SOURCE_NAME, new ConcurrentHashMap<>());
    }

    void setProperty(String key, String value) {
        getSource().put(key, value);
    }

    void removeProperty(String key) {
        getSource().remove(key);
    }

    @Override
    public Object getProperty(String key) {
        if (null == key) {
            return null;
        }
        return getSource().get(key);
    }
}
